Skip to content

added changes to your bellmanford.js#1861

Open
Ujwal200707 wants to merge 1 commit intoTheAlgorithms:masterfrom
Ujwal200707:master
Open

added changes to your bellmanford.js#1861
Ujwal200707 wants to merge 1 commit intoTheAlgorithms:masterfrom
Ujwal200707:master

Conversation

@Ujwal200707
Copy link

The change replaces the final loop with a direct return statement.
Previously, the code looped through all vertices to find the destination and then returned its distance. This loop was unnecessary because the destination index is already known.
By using:

return dis[dest]

the code becomes more efficient and readable.
It removes redundant iterations, reduces time complexity for that part from O(V) to O(1), and makes the function cleaner without affecting the output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant